/*******************************************************************************
 *  Copyright (C) 2017 iQIYI Holdings, Inc.
 *  All Rights Reserved.
 *
 *  This file is part of cloud service. Unauthorized copy of this file, via any
 *  medium is strictly prohibited. Proprietary and Confidential.
 *
 *  Author(s):
 *      Xiaoshuang LU <luxiaoshuang@qiyi.com>
*******************************************************************************/

package server;



import java.util.concurrent.atomic.AtomicLong;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class YetAnotherController {
    private static final Logger LOGGER = LoggerFactory.getLogger(YetAnotherController.class);

    private AtomicLong counter = new AtomicLong(0);

    @RequestMapping("/test/{id}")
    @ResponseBody
    public String test(Long id) {
        long value = this.counter.getAndIncrement();

        if ((value & ((1 << 8) - 1)) == 0) {
            if ((value & ((1 << 10) - 1)) != 0) {
                try {
                    Thread.sleep(10);
                } catch (Exception e) {
                    LOGGER.error("", e);
                }
            } else {
                throw new RuntimeException("all men must die.");
            }
        }

        return "all men must die.";
    }
}
